
<%@page import="java.util.ArrayList"%>
<%@page import="com.epcs.model.dto.MostFollowingList"%>
<%@page import="com.epcs.model.dto.Following"%>
<%@page import="com.epcs.util.EpcsDateTimeUtil"%>
<%@page import="com.epcs.model.dto.Event"%>
<%@page import="java.util.List"%>
<%@page import="com.epcs.model.bo.EventBO"%>
<%@page import="org.apache.struts2.dispatcher.SessionMap"%>
<%@page import="com.epcs.model.dto.Account"%>
<%@page import="com.epcs.model.bo.FollowingBO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	FollowingBO followBO = new FollowingBO();
	EventBO eventBO = new EventBO();
	Account account = (Account) session.getAttribute("USER_INFO");
	List<Object> objectList = eventBO.getTopFollowedEventByUser(0, 5, account);
	if(objectList.size() > 0){
		// xác định ng dùng đã following event hay chưa

		// kiểm tra list khác null
		List<MostFollowingList> mostFollowingList = ((List<MostFollowingList>) objectList.get(0));
		List<Event> mostListEvent = (List<Event>) objectList.get(1);

		if (mostListEvent != null) {
			if (mostListEvent.size() > 0) {
				List listNumberOfFollow = new ArrayList();
				for (int i = 0; i < mostFollowingList.size(); i++) {
					MostFollowingList mostFollowingItem = mostFollowingList
							.get(i);
					listNumberOfFollow.add(mostFollowingItem.getCountById());
				}
					for (int i = 0 ;i < mostListEvent.size() ; i ++ ){
						Event event = mostListEvent.get(i);
						long time = EpcsDateTimeUtil.compareCurrentTimeWithString(event.getStartTime());
						long temp =(time/60);
						boolean isTomorrow = EpcsDateTimeUtil.checkDateTimeIsTomorrow(event.getStartTime());
						boolean isToday = EpcsDateTimeUtil.checkDateTimeIsToday((event.getStartTime()));
				
						if(temp<0){
							event.setStartTime("Đang diễn ra");
						}else{
						
							if(isTomorrow){
								if(event.getIsAllDayEvent()){
									String date = "Ngày mai";
									event.setStartTime(date);
								}else{
									String date = EpcsDateTimeUtil.convertDateTimeWithPattern(event.getStartTime(), "HH'h' mm,") +" ngày mai";
									event.setStartTime(date);
								}
							}else if(isToday){
								if(time<60){
									String remainTime = "Còn khoảng " + String.valueOf(time)+"p";
									event.setStartTime(remainTime);
								}
								else{
									String remainTime = "Còn khoảng " + String.valueOf(temp)+ "h"+ String.valueOf(temp%60)+"p";
									event.setStartTime(remainTime);
								}
							}else{
								if(event.getIsAllDayEvent() == true){
									String inpStartTime = event.getStartTime();
									String outStartTime = EpcsDateTimeUtil.convertDateTimeWithPattern(inpStartTime, "dd-MM-yyyy");
									event.setStartTime(outStartTime);
								}else{
									String inpStartTime = event.getStartTime();
									String outStartTime = EpcsDateTimeUtil.convertDateTimeWithPattern(inpStartTime, "HH'h' mm, dd-MM-yyyy");
									event.setStartTime(outStartTime);
								}
						
							}
						}
				
				request.setAttribute("NUMBER_OF_FOLLOWING", listNumberOfFollow);
				request.setAttribute("TOP_FOLLOWING_EVENT_LIST", mostListEvent);
			}
		} 
	}
}
	
%>
<s:set var="top_folowing_event_list" value="%{#request.TOP_FOLLOWING_EVENT_LIST}" />
<s:set var="number_of_follow" value="%{#request.NUMBER_OF_FOLLOWING}" />

<s:set var="TimeOut_Event" value="%{#request.TIMEOUT_EVENT}" />
<div class="accordion-group" style="margin-top: 10px">
	    <div class="accordion-heading">      
	      	<a class="btn-info btn" data-toggle="collapse" data-parent="#dropDownSidebar" href="#collapseContent1"
	      		style="width : 100%; white-space: normal">
	       		Top 5 sự kiện của bạn đang được theo dõi nhiều nhất
	   		</a>
	    </div>
	    <div id="collapseContent1" class="accordion-body collapse in">
			<div class="accordion-inner">
			<div class="panel panel-primary" style="border-radius: 0px;">
		
				<s:if test="%{#top_folowing_event_list.isEmpty() == false}">
					<s:iterator var="top_folowing_event_item" value="%{#top_folowing_event_list}" status="counter">
						<div class="row deliverEvent_sidebar"
							style="margin-top: 5px; padding-bottom: 8px;">
							<div class="row">
								<div class="col-md-12">
									<a href="PublicEventDetail.do?id=${top_folowing_event_item.eventId}"> <span
										style="font-size: 14">${top_folowing_event_item.title}</span>
									</a>
								</div>
								
							</div>
							<div class="row">
								<div class="col-md-12">
									<b>Hiện đang có ${number_of_follow[counter.count-1]} người theo dõi</b>
								</div>
							</div>
							<div class=" row invisibleLine"></div>
								<s:if test="%{#top_folowing_event_item.startTime == 'Đang diễn ra'}">
									<div class="row">
										<div class="col-md-5">
											<b>Trạng thái: </b>
										</div>
										<div class="col-md-7">${top_folowing_event_item.startTime}</div>
									</div>
								</s:if>						
								<s:else>
								
									<div class="row">
										<div class="col-md-5">
											<b>Diễn ra: </b>
										</div>
										<div class="col-md-7">${top_folowing_event_item.startTime}</div>
									</div>
								</s:else>
						</div>
					</s:iterator>
				</s:if>
				<s:else>
					<div class="row deliverEvent_sidebar"
						style="margin-top: 5px; padding-bottom: 8px;">
						<div class="row">
							<div class="col-md-12">
								Không có sự kiện nào!
							</div>
						</div>					
					</div>
				</s:else>
			</div>
	   	</div>
	   </div>
</div>
